<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>BASE64测试</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
  <style>*{margin:0;padding:0}body{font:14px/1.5 Arial,Microsoft Yahei,sans-serif;color:#636b6f}img{border:0}a,a:focus,a:visited,a:link,a:hover,a:active{text-decoration:none}.container-fluid.main{padding:0}a{color: #636b6f;}
  </style>
</head>
<body>
  <div class="container">
    <h1>BASE64</h1>
    <div class="form-floating">
      <textarea class="form-control" id="input-area" placeholder="输入"></textarea>
      <label for="floatinginput">输入</label>
    </div>
    <br />
    <div class="text-center">
      <button type="submit" class="btn btn-outline-success" onclick="encode();">编码</button>
      <button type="submit" class="btn btn-outline-success" onclick="decode();">解码</button>
      <a class="btn btn-outline-warning" onclick="swapText();">切换至输入区</a>
    </div>
    <br />
    <div class="form-floating">
      <textarea class="form-control" id="output-area" placeholder="输入"></textarea>
      <label for="floatinginput">输出</label>
    </div>
    <br>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
  <script>
    let ipt=document.getElementById('input-area');
    let opt=document.getElementById('output-area');
    function swapText() {ipt.value=opt.value;opt.value="";};
    function encode(){opt.value=btoa(unescape(encodeURIComponent(ipt.value)))};
    function decode(){opt.value=decodeURIComponent(escape(atob(ipt.value)))};
  </script>
</body>
</html>
